package srting;

public class Test {
    public static void main(String[] args) {
        String name1 =getHostName("http://www.tedu.cn");
        String name2 =getHostName("doc.canglaoshi.org");
        String name3 =getHostName("www.tarena.com.cn");
        System.out.println(name1);//tedu
        System.out.println(name2);//canglaoshi
        System.out.println(name3);//tarena

    }
    public static String getHostName(String location){
        //1:先找到location中第一个"."和第二个"."的位置.方法:indexOf
        int det=location.indexOf(".");
        int det1=location.indexOf(".",det+1);
        //2:截取两个"."之间的字符串.方法:substring
        String a=location.substring(det+1,det1);

        return a;
    }

}
